package zhou.chs.p2_11;

import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    ConstraintLayout cl1,cl2,cl3;  //声明3个约束布局，分别容纳3个界面的控件
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cl1=(ConstraintLayout)findViewById(R.id.idcl1);     //控件实例化
        cl2=(ConstraintLayout)findViewById(R.id.idcl2);
        cl3=(ConstraintLayout)findViewById(R.id.idcl3);
        cl1.setVisibility(View.VISIBLE);    //先显示界面一
        cl2.setVisibility(View.INVISIBLE);
        cl3.setVisibility(View.INVISIBLE);
    }
    @Override  //程序界面加载菜单
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.mm, menu);
        return true;
    }
    @Override //菜单选项选择响应
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.idm1) {
            cl1.setVisibility(View.VISIBLE);    //显示界面一
            cl2.setVisibility(View.INVISIBLE);
            cl3.setVisibility(View.INVISIBLE);
            return true;
        }
        if (id == R.id.idm2) {
            cl2.setVisibility(View.VISIBLE);    //显示界面二
            cl1.setVisibility(View.INVISIBLE);
            cl3.setVisibility(View.INVISIBLE);
            return true;
        }
        if (id == R.id.idm3) {
            cl3.setVisibility(View.VISIBLE);    //显示界面三
            cl1.setVisibility(View.INVISIBLE);
            cl2.setVisibility(View.INVISIBLE);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
